package com.youshang520i.springcommonmiddleware.mq.rocketmq;

import lombok.extern.log4j.Log4j2;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 */
@Log4j2
@Configuration
public class MQProducerConfig {

    @Value("${rocketmq.name-server}")
    private String nameSrvAddr;

    @Bean(destroyMethod = "shutdown")
    public DefaultMQProducer mqProducer() throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("test-producer");
        producer.setNamesrvAddr(nameSrvAddr);
        //取消当前消息走VIP Channel
        producer.setVipChannelEnabled(false);
        producer.setSendMsgTimeout(5000);
        producer.start();
        log.info("RocketMQ.........启动成功！！！！");
        return producer;
    }
}
